package sg.edu.nus.iss.vmcs.system;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class FilePropertyLoaderImpl implements PropertyLoaderImpl {
	
	private String fileName;
	
	public FilePropertyLoaderImpl(String fileName) {
		this.fileName = fileName;
	}

	/**
	 * This method reads the properties file into a hash table.
	 * @throws IOException if fail to load properties from properties file.
	 */
	public void initialize(Properties prop) throws IOException {		
		FileInputStream stream = new FileInputStream(fileName);
		prop.load(stream);
		stream.close();
	}
	
	/**
	 * This method writes the properties from the hash table to the file.
	 * @throws IOException if fail to store properties to properties file.
	 */	
	public void saveProperty(Properties prop) throws IOException {
		FileOutputStream stream = new FileOutputStream(fileName);
		prop.store(stream, "");
		stream.close();
	}
}
